<template>
  <BasicModal
    v-bind="$attrs"
    @register="register"
    okText="统计"
    width="500px"
    :title="displayModuleTitle"
    @ok="onOkButtonClick"
  >
    <a-form :model="tmstsCondition">
      <a-form-item
        label="段次类型值"
        :labelCol="{ style: 'width:100px' }"
        :rules="[{ required: true }]"
        style="width: 95%"
      >
        <a-select
          v-model:value="tmstsCondition.intervaltype"
          :options="timeIntervalOptions"
        ></a-select> </a-form-item
      ><a-form-item
        label="段次长度"
        :labelCol="{ style: 'width:100px' }"
        :rules="[{ required: true }]"
        style="width: 95%"
      >
        <a-input-number
          id="inputNumber"
          style="width: 100%"
          v-model:value="tmstsCondition.intlength"
          :min="1"
        />
      </a-form-item>
    </a-form>
  </BasicModal>
</template>
<script lang="ts">
  import { computed, defineComponent, onMounted, ref, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { displayTitle } from '/@/utils/QcUnifyUtil';
  import { OperationTypeEnum } from '/@/enums/appEnum';
  import { QcUnifyTransToChildProps } from '/#/QcUnify';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { queryEnumOptions } from '/@/api/platform/enum';
  const { createMessage } = useMessage();
  export default defineComponent({
    components: { BasicModal, BasicForm },
    name: 'SetTimeStsCondition',
    emits: ['success'],
    setup(props, { emit }) {
      const operateType = ref(OperationTypeEnum.UN_KNOWN);
      /**
       * 按时间规整数据的额外查询条件
       */
      const tmstsCondition = ref({
        intervaltype: '2',
        intlength: 1,
      });
      /**
       * 段次类型值
       */
      const timeIntervalOptions = ref([]);
      const [registerForm, { setFieldsValue, resetFields, validate, updateSchema }] = useForm({
        labelWidth: 140,
        // schemas: confirmIdentifyFormSchema,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
      const qcUnifyProps = ref<QcUnifyTransToChildProps>();
      const dataId = ref();
      const [register, { closeModal }] = useModalInner((data) => {
        if (data != undefined && data != null) {
          let unrefData = unref(data);
          qcUnifyProps.value = unrefData;
          //接收父组件传递的数据
          if (unrefData?.operateType) {
            //判断是否传入op属性
            operateType.value = unrefData.operateType;
          }
        }
      });
      function onOkButtonClick() {
        emit('success', tmstsCondition.value);
        closeModal();
      }

      let displayModuleTitle = computed(() => {
        return displayTitle(qcUnifyProps.value);
      });
      onMounted(() => {
        queryEnumOptions('TimeRangeLengthEnum').then((res) => {
          timeIntervalOptions.value = res[0].options.map((option) => {
            return {
              value: option.key,
              label: option.value,
            };
          });
        });
      });
      return {
        register,
        registerForm,
        closeModal,
        displayModuleTitle,
        onOkButtonClick,
        tmstsCondition,
        timeIntervalOptions,
      };
    },
  });
</script>
